const App = getApp();
Page({
    data: {
        user: "",
        config: "",
        renwu: [],
        num: 0,
        scrollLeft: 0,
        scrollWithAnimation: true
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getuser();
        this.getconfig();

        const query = wx.createSelectorQuery()
        query.select('.marquee').boundingClientRect()
        query.exec(res => {
            const width = res[0].width
            // 设置定时器，每隔一段时间滚动一次
            setInterval(() => {
                let scrollLeft = this.data.scrollLeft + 1
                if (scrollLeft >= width) {
                    scrollLeft = 0
                }
                this.setData({
                    scrollLeft: scrollLeft
                })
            }, 20)
        })

    },
    getconfig: function () {
        var that = this;

        App._post_form('wxapi/config', {}, function (result) {
            console.log("config", result);
            that.setData({
                config: result.data,

            })
        });
    },
    getuser: function () {
        var that = this;
        var token = wx.getStorageSync('token');
        App._post_form('wxapi/myinfo', {
            token: token
        }, function (result) {
            console.log("user", result);
            that.setData({
                user: result.data,

            })
        });
    },
    shuaxin() {
        this.getrenwu();
    },
    daitijiao() {
        this.getuserrenwu();
    },
    getrenwu: function () {
        var that = this;
        var token = wx.getStorageSync('token');
        App._post_form('wxapi/v2/renwu/list', {
            token: token
        }, function (result) {
            console.log("user", result);
            that.setData({
                renwu: result.data,

            })
        });
    },
    getuserrenwu: function () {
        var that = this;
        var token = wx.getStorageSync('token');
        App._post_form('wxapi/v2/renwu/user', {
            token: token
        }, function (result) {
            console.log("user", result);
            that.setData({
                renwu: result.data,

            })
        });
    },
    getusernum: function () {
        var that = this;
        var token = wx.getStorageSync('token');
        App._post_form('wxapi/renwu/user/num', {
            token: token
        }, function (result) {
            console.log("user", result);
            that.setData({
                num: result.data,

            })
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getrenwu();
        this.getusernum();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },
    joinuser(e) {
        var id = e.currentTarget.dataset.id;
        var orderid = e.currentTarget.dataset.orderid;
        console.log("orderid", orderid);
        wx.navigateTo({
            url: "/pages/task-detail/task-detail?id=" + id + "&orderid=" + orderid,
        })
    },
    join(e) {
        console.log("e", e);
        var id = e.currentTarget.dataset.id;
        var token = wx.getStorageSync('token');
        App._post_form('wxapi/v2/orders/add', {
            token: token,
            renwuid: id
        }, function (result) {
            console.log("use111111111111111111111r", result);

            var orderid = result.data;
            wx.navigateTo({
                url: "/pages/task-detail/task-detail?id=" + id + "&orderid=" + orderid,
            })
        });



    },
    jilu() {
        wx.navigateTo({
            url: "/pages/jilu/jilu",
        })
    },
    test() {
        wx.navigateToMiniProgram({
            appId: "wx95721458c1ca722e",
            path: "/pages/index/index",
            extraData: {
                foo: 'bar'
            },
            success: res => {


            },
            fail: error => {

            },
        })
    },
    fangqi(e) {
        var that = this;
        var orderid = e.currentTarget.dataset.orderid;
        wx.showModal({
            title: '系统提示',
            content: '确定要放弃吗',
            success(res) {
                if (res.confirm) {

                    var token = wx.getStorageSync('token');
                    App._post_form('wxapi/orders/del', {
                        token: token,
                        orderid: orderid
                    }, function (result) {

                        that.getuserrenwu();
                        that.getusernum();

                    });


                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })


    },
    jiebang() {
        console.log("111")
        wx.showModal({
            title: '系统提示',
            content: '确定要解绑吗',
            success(res) {
                if (res.confirm) {
                    console.log('用户点击确定')
                    var token = wx.getStorageSync('token');
                    App._post_form('wxapi/jiebang', {
                        token: token
                    }, function (result) {
                        wx.reLaunch({
                            url: "/pages/index/index",
                        })

                    });


                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })

    },
    del(e) {
        var id = e.currentTarget.dataset.id;
        var that = this;
        wx.showModal({
            title: '系统提示',
            content: '确定要下架吗',
            success(res) {
                if (res.confirm) {
                    console.log('用户点击确定')
                    var token = wx.getStorageSync('token');
                    App._post_form('wxapi/renwu/del', {
                        id: id,
                        token: token
                    }, function (result) {

                        that.getrenwu();

                    });


                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })
    },
})